package com.runjian.rundo.iot.agent.business.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.runjian.rundo.iot.agent.common.entity.AgentProtocolDTO;
import com.runjian.rundo.iot.agent.common.manager.ProtocolManager;

import cn.hutool.core.map.multi.RowKeyTable;
import cn.hutool.core.map.multi.Table;
import cn.hutool.core.util.ObjectUtil;

/**
 * IoT设备服务接口
 *
 * @author LiGang
 * @date 2023/4/13 22:02
 */
public class BaseProtocolManagerImpl<T extends AgentProtocolDTO> implements ProtocolManager<T> {

    private Map<String, T> protocolMap = new HashMap<>();

    /**
     * 设备缓存列表
     */
    private static final Table<String, String, AgentProtocolDTO> gatewayDeviceMap = new RowKeyTable();

    @Override
    public T getProtocol(String id) {
        return protocolMap.get(id);
    }

    @Override
    public void addLocalProtocolList(List<T> protocolList) {
        if (ObjectUtil.isEmpty(protocolList)) {
            return;
        }
        protocolList.forEach(protocol -> {
            protocolMap.put(protocol.getId(), protocol);
        });
    }
}
